﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Web;

namespace ST.Buz.Api
{
	public class Program
	{
		public static void Main(string[] args)
		{
			// NLog: setup the logger first to catch all errors
#if DEBUG
			var logger = NLogBuilder.ConfigureNLog("nlog.Debug.config").GetCurrentClassLogger();
#else
			var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
#endif
			try
			{
				logger.Debug("应用开始启动...");
				CreateWebHostBuilder(args).Build().Run();
			}
			catch (Exception ex)
			{
				logger.Error(ex, "应用异常中止");
				throw;
			}
			finally
			{
				NLog.LogManager.Shutdown();
			}
		}

		public static IWebHostBuilder CreateWebHostBuilder(string[] args)
		{
			return WebHost.CreateDefaultBuilder(args)
				//.UseSetting("https_port", "443")//配置https端口
				.ConfigureLogging((ctx, logging) =>
				{
					logging.AddNLog();
				})
				.UseStartup<Startup>();
		}
	}
}
